/**
 * Created on 2007-05-19 03:04
 */
package game.frames;

import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextArea;

/**
 * @author David Wallin
 */
public class InstructionsFrame extends BasicFrame
{
	/**
	 * 
	 */
	private static final long		serialVersionUID = 4726026295809795213L;
	private JLabel					m_Header;
	private JTextArea				m_Instructions;
	private JButton					m_Main;
	
	/**
	 * 
	 */
	public InstructionsFrame()
	{
		super(new GridBagLayout());
	}
	
	/* (non-Javadoc)
	 * @see frames.BasicFrame#initializeComponent()
	 */
	@Override
	protected void initializeComponent()
	{
		this.setBackground(Color.black);
		GridBagLayout gridBag = (GridBagLayout)this.getLayout();
		
		GridBagConstraints headerConstraints = new GridBagConstraints();
		headerConstraints.insets = new Insets(10, 0, 0, 0);
		headerConstraints.gridx = 1;
		headerConstraints.gridy = 0;
		headerConstraints.gridwidth = 1;
		headerConstraints.weightx = 0.5;
		
		GridBagConstraints scoreBoardConstraints = new GridBagConstraints();
		scoreBoardConstraints.gridx = 0;
		scoreBoardConstraints.gridy = 1;
		scoreBoardConstraints.gridwidth = 3;
		
		GridBagConstraints mainConstraints = new GridBagConstraints();
		mainConstraints.gridx = 1;
		mainConstraints.gridwidth = 1;
		mainConstraints.weightx = 0.5;
		mainConstraints.weighty = 1.5;
		mainConstraints.anchor = GridBagConstraints.SOUTH;
		
		m_Header = new JLabel("Instructions");
		m_Instructions = new JTextArea(	"Control the falling pieces to make them form full\n" +
										"lines. You can only spin the middle piece, or - if there\n" +
										"is less than 2 pieces on screen - the one in the\n" +
										"preview box.\n\n" + 
										
										"When a line is formed, it is removed, and the blocks\n" +
										"on top of it falls down, making room for more blocks.\n" +
										"When there is no room for more blocks the game is\n" +
										"over.\n\n" +
										
										"Gain more points by removing several blocks at a\n" +
										"time. Every 3 lines, you advance a level, making the\n" +
										"pieces fall faster, but the removed lines worth more\n" +
										"points.\n\n" +
										
										"Good luck!");
		m_Main = new JButton("Main screen");
		
		Font f = new Font("Times", Font.BOLD, 14);
		m_Header.setFont(f);
		m_Header.setHorizontalAlignment(JLabel.CENTER);
		m_Header.setVerticalAlignment(JLabel.CENTER);
		m_Header.setBackground(Color.black);
		m_Header.setForeground(Color.gray);
		
		m_Instructions.setEditable(false);
		m_Instructions.setBackground(Color.black);
		m_Instructions.setForeground(Color.white);
		
		m_Instructions.setLineWrap(false);
		//m_Instructions.setPreferredSize(new Dimension(200, 400));
		m_Main.addActionListener(this);
		
		this.addComponent(m_Header, gridBag, headerConstraints);
		this.addComponent(m_Instructions, gridBag, scoreBoardConstraints);
		this.addComponent(m_Main, gridBag, mainConstraints);
		
		this.doLayout();
	}
	
	/* (non-Javadoc)
	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
	 */
	public void actionPerformed(ActionEvent event)
	{
		Object source = event.getSource();
		
		if(source == m_Main)
		{
			this.updateFrameSwitchListeners(Frames.MAIN_MENU);
		}
	}
}
